import 'package:flutter_base/base/controller/base_list_more_controller.dart';
import 'package:flutter_base/config/app_routes.dart';
import 'package:flutter_base/http/api.dart';
import 'package:flutter_base/http/http_manager.dart';
import 'package:flutter_base/http/ui/http_enum.dart';
import 'package:flutter_base/pages/mine/test_history/model/model_test_history.dart';
import 'package:flutter_base/utils/log/utils_log.dart';

// import 'package:flutter_base/pages/mine/test_history/model/test_history_model.dart';
import 'package:get/get.dart';

class TestHistoryListLogic extends BaseListMoreController {
  // 测试类型：0-未完成，1-已完成
  final int type;

  TestHistoryListLogic({this.type = 1});

  @override
  void onReady() {
    super.onReady();
    refreshList();
  }

  @override
  void onClose() {
    super.onClose();
    clog('dis  TestHistoryListLogic');
  }

  @override
  Future<List> loadData() async {
    // 调用API获取测试历史数据
    Map<String, dynamic> params = {
      'page': pageNum,
      'size': pageSize,
      'status': type,
    };

    var response = await HttpManager().get(API.userTestHistory,
        params: params,
        uiType: HttpUIType.toast,
        fromJson: ModelTestHistory.fromJson);

    return response.data ?? [];
  }

  // 生成报告
  void onGenerateReport(ModelTestHistory test) {
    // TODO: 实现生成报告逻辑
    clog('onGenerateReport');
  }

  // 再次测试
  void onTestAgain(ModelTestHistory test) {
    clog('onTestAgain');

    // TODO: 实现再次测试逻辑
  }

  // // 查看详情
  void onViewDetails(ModelTestHistory test) {
    clog('daslkdjalskjd');
    Get.toNamed(AppRoutes.testResult, arguments: {
      'userTestId': test.id,
    });
    // TODO: 实现查看详情逻辑
  }
}
